package com.lvmama.controller.rhino.superfreetravel;

import com.github.pagehelper.PageInfo;
import com.lvmama.client.rhino.SuperfreetravelClient;
import com.lvmama.common.utils.StringUtils;
import com.lvmama.pojo.entity.rhino.superfreetravel.PageView;
import com.lvmama.pojo.entity.rhino.superfreetravel.PageViewVo;
import com.lvmama.pojo.entity.rhino.superfreetravel.SearchListVo;
import com.lvmama.pojo.entity.rhino.superfreetravel.SuperfreeFlowstatistic;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @param
 * @Title:
 * @Author:wangpeng
 * @Description: TODO(这里用一句话描述这个方法的作用)
 * @return
 * @throws
 */
@Controller
@Slf4j
@RequestMapping(value = "/superfreetravel")
public class SuperfreetravelController {
	@Autowired
	SuperfreetravelClient client;

	/**
	 * 页面访问量
	 * @return
	 */
	@RequestMapping(value = "/visitPage",method = RequestMethod.GET)
	public String visitPage(){
		return "rhino/superfreetravel/visitPage";
	}

	/**
	 * 页面元素流量
	 * @return
	 */
	@RequestMapping(value = "/visitFlow",method = RequestMethod.GET)
	public String visitFlow(){
		return "rhino/superfreetravel/visitFlow";
	}

	/**
	 * 页面元素流量数据接口
	 * @param searchListVo
	 * @return
	 */
	@RequestMapping(value = "/clickVolume",method = RequestMethod.GET)
	@ResponseBody
	PageInfo<SuperfreeFlowstatistic> clickVolume(SearchListVo searchListVo){
		log.info("SuperfreetravelController clickVolume start");
		PageInfo<SuperfreeFlowstatistic> result = null;
		String chooseDate = searchListVo.getChooseDate();
		try {
			// 查询日期条件处理
			if( chooseDate != null ){
				String[] days = chooseDate.split("-");
				searchListVo.setStartDate(StringUtils.toDateStr(days[0].trim()));
				searchListVo.setEndDate(StringUtils.toDateStr(days[1].trim()));
			}
			result = client.clickVolume(searchListVo);
		}catch (Exception e){
			log.error("SuperfreetravelController clickVolume error",e.getMessage(),e);
		}
		log.info("SuperfreetravelController clickVolume end");
		return result;
	}

	/**
	 * 页面访问量数据接口
	 * @param pageViewVo
	 * @return
	 */
	@RequestMapping(value = "/visitPageData",method = RequestMethod.GET)
	@ResponseBody
	PageInfo<PageView> visitPage(PageViewVo pageViewVo){
		log.info("SuperfreetravelController visitPage start");
		PageInfo<PageView> result = null;
		String chooseDate = pageViewVo.getChooseDate();
		try {
			// 查询日期条件处理
			if( chooseDate != null ){
				String[] days = chooseDate.split("-");
				pageViewVo.setStartDate(StringUtils.toDateStr(days[0].trim()));
				pageViewVo.setEndDate(StringUtils.toDateStr(days[1].trim()));
			}
			result = client.queryPVAndUV(pageViewVo);
		}catch (Exception e){
			log.error("SuperfreetravelController visitPage error:",e.getMessage(),e);
		}
		log.info("SuperfreetravelController visitPage end");
		return result;
	}
}
